define(['../../carrys/cityList','../../carrys/jsonList','../../../../js/lib/other/sweet-alert'],function(cityData,jsonList) {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','8');//显示底部文字
    	
    	$scope.isslide_up = false;//默认擅长领域
    	var caseTypeList = jsonList.caseTypeData;
    	caseTypeList.forEach(function(e){
    		e.sel = false;
    	});
    	var goodFieldNum;
    	
    	var provinceList = new Array();
    	var cityListTemp = new Array();
    	$scope.lawyerNo = "",
    	$scope.provinceName = "",$scope.cityName ="",
    	$scope.goodField = "",$scope.bankName = "",$scope.bankNo = "",$scope.branchName = "",$scope.accountName = "";
    	
    	collateData();//整理列表数据
    	
    	//显示省份
    	$scope.provinceData = provinceList;
    	
    	//显示城市
    	$scope.clickCity = function(){
    		var cityList = new Array();
    		var provinceName = ($scope.provinceName).province;
    		for(var i=0;i<cityListTemp.length;i++){
    			if(cityListTemp[i].province == provinceName){
    				var tempData = {'city': cityListTemp[i].city};
    				cityList.push(tempData);
    			}
    		}
    		$scope.cityData = cityList;
    	}
    	
    	//点击显示擅长领域
    	$scope.showField = function(){
    		$scope.isslide_up = true;
    		$scope.caseTypeList = caseTypeList;
    	}
    	
    	//点击关闭擅长领域
    	$scope.closeType = function(){
    		$scope.isslide_up = false;
    	}
    	
    	//选择案件类型
    	$scope.selectType = function(flag){
    		if(caseTypeList[flag].sel){
    			caseTypeList[flag].sel = false;
    		}else{
    			caseTypeList[flag].sel = true;
    		}
    		
    	}
    	
    	//确认选择
    	$scope.confirmBtn = function(){
			var tempString = "",tempFieldString = "";
			for(var i=0;i<caseTypeList.length;i++){
				if(caseTypeList[i].sel){
					tempString = tempString + caseTypeList[i].name + "_";
					tempFieldString = tempFieldString + caseTypeList[i].val + "_";
				}
			}
			$scope.goodField = tempString.substring(0,tempString.length-1);
			goodFieldNum = tempFieldString.substring(0,tempFieldString.length-1);
    		$scope.isslide_up = false;
    	}
    	
    	//点击提交
        $scope.subConfirm = function(){
    		if(! $scope.lawyerNo){
    			$scope.$emit("promptAlertMsg","律师证号不能为空");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(($scope.lawyerNo).length != 17 || isNaN($scope.lawyerNo *1)){
    			$scope.$emit("promptAlertMsg","律师证号格式不正确");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else{
    			subLsData();
    		}
        }
        
      //调用代理提交律师用户完善资料
        function subLsData(){
        	var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	if($routeParams.flag != "" && $routeParams.flag != null){
        		var tempString = $routeParams.flag;
        		bizInfo = JSON.parse(tempString);
        	}
        	bizInfo.lawyerNo = $scope.lawyerNo;
        	try{
        		if(!($scope.provinceName).province || !($scope.cityName).city){
            		bizInfo.advArea = "";
            	}else{
            		bizInfo.advArea = ($scope.provinceName).province + "_" + ($scope.cityName).city;
            	}
        	}catch(e){
        		bizInfo.advArea = "";
        	}
        	
        	bizInfo.advField = goodFieldNum;
        	bizInfo.inviteCode = resultData.loginUserData.inviteCode;
        	// bizInfo.bankName = "";
        	// bizInfo.accountNo = "";
        	// bizInfo.branchName = "";
        	// bizInfo.accountName = "";
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("userExt4Lawyer",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
    					$scope.$emit("loadingChange",false);
    					assignmentData(tempData);
    					var tempBody = JSON.parse(tempData.body);
    					console.log(tempData.body)
    						$scope.$emit("goNext","/mineLs");
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginResultData = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									$scope.$emit("goNext","/mineLs");
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit("loadingChange",false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    					$scope.$emit("goNext","/mineLs");
		    				},transData.promptTime);
		    			}
		    		});
        }
        
    	//监听跳过点击事件
    	$scope.$on('skipEvent', function(event,data){
    		if(data){
    			$scope.$emit("goNext","/minePt");
    		}
        });
    	
    	
    	//整理省市数据
    	function collateData() {
    		cityListTemp = new Array();
			for(var key in cityData.addressDetail){
				var tempData = {"province":key};
				provinceList.push(tempData);
				collateCity(key,cityData.addressDetail[key]);
			}
    	}
		function collateCity(data1,data2) {
			for(var key in data2){
				var tempList = {'province':data1,'city': key};
				cityListTemp.push(tempList);
			}
		}
    	
        $scope.$apply();
    }];
});